package com.xbk.seckill.order.application.service.impl;

import com.xbk.seckill.common.constants.SeckillConstants;
import com.xbk.seckill.common.model.dto.SeckillOrderSubmitDTO;
import com.xbk.seckill.order.application.model.command.SeckillOrderCommand;
import com.xbk.seckill.order.application.service.SeckillSubmitOrderService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 同步提交订单
 *
 * @author xiexu
 * @date 2025/3/2 17:26
 */
@Service
// 当配置文件中submit.order.type的值为sync时，才会创建这个bean
@ConditionalOnProperty(name = "submit.order.type", havingValue = "sync")
public class SeckillSyncSubmitOrderServiceImpl extends SeckillBaseSubmitOrderServiceImpl implements SeckillSubmitOrderService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public SeckillOrderSubmitDTO saveSeckillOrder(Long userId, SeckillOrderCommand seckillOrderCommand) {
        // 进行基本的检查
        this.checkSeckillOrder(userId, seckillOrderCommand);
        // 下单
        Long placeOrderResult = seckillPlaceOrderService.placeOrder(userId, seckillOrderCommand);
        return new SeckillOrderSubmitDTO(String.valueOf(placeOrderResult), seckillOrderCommand.getGoodsId(), SeckillConstants.TYPE_ORDER);
    }

}
